package com.jpa.web.service;

import com.jpa.web.model.Employee;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by BKWJA on 2018/10/27.
 * 针对 Repository 更新，删除操作
 */
public class EmployeeServiceImplTestCrud {

    private EmployeeServiceCrud employeeServiceCrud;
    private ApplicationContext context = null;

    /**
     * 在……之前
     */
    @Before
    public void setup(){
        context = new ClassPathXmlApplicationContext("spring-jpa.xml");
        employeeServiceCrud = context.getBean(EmployeeServiceCrud.class);
        System.out.println("setup");
    }

    /**
     * 在……之后
     */
    @After
    public void tearDown(){
        context = null;
        System.out.println("tearDown");
    }

    /**
     * 保存 添加多条记录
     */
    @Test
    public void insertEmployeeTest(){
       List<Employee> employeeList = new ArrayList<Employee>();
        Employee employee = new Employee();
        employee.setEmpname("admin");
        employee.setEmpage(21);
        employee.setEmpsex("女");
        employee.setDepartment("技术部");
        employee.setCreateTime(new Date());
        employee.setUpateTime(new Date());
        employeeList.add(employee);

        Employee emp = new Employee();
        emp.setEmpname("张会");
        emp.setEmpage(21);
        emp.setEmpsex("女");
        emp.setDepartment("技术部");
        emp.setCreateTime(new Date());
        emp.setUpateTime(new Date());
        employeeList.add(emp);

        employeeServiceCrud.save(employeeList);
    }


}
